<?php

namespace App\Http\Controllers\Admin;


use App\Http\Requests;
use App\Http\Controllers\Controller;

use Excel;

class ExcelController extends Controller
{
    public function export(){
        $cellData = [
            ['学号','姓名','成绩'],
            ['10001','AAAAA','99'],
            ['10002','BBBBB','92'],
            ['10003','CCCCC','95'],
            ['10004','DDDDD','89'],
            ['10005','EEEEE','96'],
        ];
        $name = iconv('UTF-8', 'GBK', '学生成绩');
//        Excel::create($name,function($excel) use ($cellData){
//            $excel->sheet('score', function($sheet) use ($cellData){
//                $sheet->rows($cellData);
//            });
//        })->export('xls');
        Excel::create($name,function($excel) use ($cellData){
            $excel->sheet('score', function($sheet) use ($cellData){
                $sheet->rows($cellData);
            });
        })->store('xls')->export('xls');
    }

    //Excel文件导入功能 By Laravel学院
    public function import(){
        $filePath = 'public/uploads/else/'.iconv('UTF-8', 'GBK', 'excel').'.xls';
        Excel::load($filePath, function($reader) {
            dd( $reader->all()->toArray());
        });
    }
}
